package com.ufaud.ais.sys.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import com.ufaud.ais.pub.entity.BaseEntity;

/**
 * 功能：自定义项类型
 * @author 林可
 * @version 1.0 2010-7-21
 */
@Entity
@Table(name = "custom_item_type")
public class CustomItemType extends BaseEntity<Long>{

	private Long itemTypeId;
	private String itemTypeName;
	private String itemTypeDesc;
	private Set<CustomItem> customItemSet = new HashSet<CustomItem>();

	@Id
	@GeneratedValue
	@Column(name="item_type_id")
	public Long getItemTypeId() {
		return itemTypeId;
	}

	@Column(name="item_type_name")
	public String getItemTypeName() {
		return itemTypeName;
	}

	@Column(name="item_type_desc")
	public String getItemTypeDesc() {
		return itemTypeDesc;
	}

	@OneToMany(fetch=FetchType.LAZY, targetEntity=CustomItem.class, mappedBy="itemType")
	@Cascade( { CascadeType.ALL, CascadeType.DELETE_ORPHAN })
	public Set<CustomItem> getCustomItemSet() {
		return customItemSet;
	}

	public void setItemTypeId(Long itemTypeId) {
		this.itemTypeId = itemTypeId;
	}

	public void setItemTypeName(String itemTypeName) {
		this.itemTypeName = itemTypeName;
	}

	public void setItemTypeDesc(String itemTypeDesc) {
		this.itemTypeDesc = itemTypeDesc;
	}

	public void setCustomItemSet(Set<CustomItem> customItemSet) {
		this.customItemSet = customItemSet;
	}

	public void addCustomItem(CustomItem customItem) {
		customItem.setItemType(this);
		getCustomItemSet().add(customItem);
	}

	@Override
	@Transient
	public String getPropertyNameOfId() {
		return "itemTypeId";
	}
}
